<?php
/**
 * @filename:					GraveyardAction.class.php
 * @desc:						墓地管理模块
 *
 * @author: 					张召
 * @copyright:					zhangzhao@huigeyuan.com
 * @date:						2011-04-19
 */


class GraveyardAction extends CommonAction
{
    function _initialize() {
		parent::_initialize();
		//墓型
        $type = new GraveyardTypeModel();
        $typename = $type->select();
        $this->assign('typename',$typename);
        //园
        $garden = new GardenModel();
        $gardenname = $garden->select();
        $this->assign('gardenname',$gardenname);
        //状态
        $state = D('graveyard_state');
        $statename = $state->select(); 
        $this->assign('statename',$statename);
        $this->id();
    }
 /**
 * 获取当前区的id
 *
 */    
    function id()
    {
		//传值id
		if ($_SERVER['REQUEST_METHOD'] == 'GET') {
			$id = $_GET['id'];
		} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
			$id = $_POST['district_id'];
		}   	
        //查询排
        $district = D('district');
		$qu = $district->where("id=$id")->find();//查询所在区
		$this->assign('qu',$qu);
        $groupname = $district->where("pid=$id")->select();//查询排
        $this->assign('groupname',$groupname); 
        
        $graveyard = D('graveyard');
        $list = $graveyard->select();
        $this->assign('list',$list);
        $this->assign('id',$id);
    }

    /**
    * 墓地展示
    */
    function index()
    {
    	$crumb_info = array(
			array('uri' => '__URL__', 'title' => L('Graveyard_manage'), 'sort' => C('CRUMB_LAST')),
		);

		$this->_mergeCrumbInfo($crumb_info);

		$this->assign('crumb_info', $this->_crumb_info);		
        $this->display();
    }
    /**
    * 添加新的墓地
    */
    public function add()
    {
       $crumb_info = array(
			array('uri' => '__URL__', 'title' => L('Graveyard_manage'), 'sort' => C('CRUMB_DEFAULT')),
			array('uri' => '__URL__/add', 'title' => L('add_Graveyard'), 'sort' => C('CRUMB_LAST')),
		);

		$this->_mergeCrumbInfo($crumb_info);
		$this->_action_link = array(
			array('uri' => '__URL__/index', 'title' => L('list_Graveyard')),
			);

		$this->assign('crumb_info', $this->_crumb_info);
		$this->assign('action_link', $this->_action_link);
		
		
		parent::add();
    }
    
   /**
    * 添加新的排
    */
    public function addrow()
    {
       $crumb_info = array(
			array('uri' => '__URL__', 'title' => L('Graveyard_manage'), 'sort' => C('CRUMB_DEFAULT')),
			array('uri' => '__URL__/add', 'title' => L('add_Graveyard'), 'sort' => C('CRUMB_LAST')),
		);

		$this->_mergeCrumbInfo($crumb_info);
		$this->_action_link = array(
			array('uri' => '__URL__/index', 'title' => L('list_Graveyard')),
			);

		$this->assign('crumb_info', $this->_crumb_info);
		$this->assign('action_link', $this->_action_link);		
		
		parent::add();
    }
	function insertrow() {
//		dump($_POST);die;
		$model = new DistrictModel();
		if (false === $model->create ()) {
			$this->error ( $model->getError () );
		}
		//保存当前数据对象
		$list=$model->add ();
		if ($list!==false) { //保存成功
			$this->assign ( 'jumpUrl', Cookie::get ( '_currentUrl_' ) );
			$this->success ('新增成功!');
		} else {
			//失败提示
			$this->assign ( 'jumpUrl', Cookie::get ( '_currentUrl_' ) );
			$this->error ('新增失败!');
		}
	}
 /**
    * 修改排
    */
    public function editrow()
    {
       $crumb_info = array(
			array('uri' => '__URL__', 'title' => L('Graveyard_manage'), 'sort' => C('CRUMB_DEFAULT')),
			array('uri' => '__URL__/add', 'title' => L('add_Graveyard'), 'sort' => C('CRUMB_LAST')),
		);

		$this->_mergeCrumbInfo($crumb_info);
		$this->_action_link = array(
			array('uri' => '__URL__/index', 'title' => L('list_Graveyard')),
			);

		$this->assign('crumb_info', $this->_crumb_info);
		$this->assign('action_link', $this->_action_link);		
		
		parent::add();
    }
	function updaterow() {
//		dump($_GET);die;
		$model = new DistrictModel();
		if (false === $model->create ()) {
			$this->error ( $model->getError () );
		}
		// 更新数据
		$list=$model->save ();
	
		if (false !== $list) {
			//成功提示
			$this->assign ( 'jumpUrl', Cookie::get ( '_currentUrl_' ) );
			$this->success ('编辑成功!');
		} else {
			//错误提示
			$this->error ('编辑失败!');
		}
	}

    /**
    * 查看墓地的详细信息
    */
    public function view()
    {
       $crumb_info = array(
			array('uri' => '__URL__', 'title' => L('Graveyard_manage'), 'sort' => C('CRUMB_LAST')),
		);

		$this->_mergeCrumbInfo($crumb_info);
		$this->_action_link = array(
			array('uri' => '__URL__/index', 'title' => L('list_Graveyard')),
		);
		$this->assign('crumb_info', $this->_crumb_info);
		$this->assign('action_link', $this->_action_link);
		parent::view();
    }

    /**
    * 修改或完善墓地信息
    */
    public function edit()
    {
       $crumb_info = array(
			array('uri' => '__URL__', 'title' => L('Graveyard_manage'), 'sort' => C('CRUMB_DEFAULT')),
			array('uri' => '__URL__/edit/id/' . $_REQUEST['id'], 'title' => L('edit_Graveyard'), 'sort' => C('CRUMB_LAST')),
		);

		$this->_mergeCrumbInfo($crumb_info);
		$this->_action_link = array(
			array('uri' => '__URL__/index', 'title' => L('list_Graveyard')),
			);

		$this->assign('crumb_info', $this->_crumb_info);
		$this->assign('action_link', $this->_action_link);
		parent::edit();
    }

    /**
    * 删除当前墓地记录
    */
    public function delete()
    {
       parent::delete();
    }
  	
//验收展示
  	public function check()
  	{
  		parent::index();
  	}
  	
//验收
  	public function accept()
  	{
  		$id = $_REQUEST['id'];
  	
  		$this->assign('id',$id);
		parent::edit();
  		
  	}

	function update1() {

		$name=$this->getActionName();
		$model = D ( $name );
		$state_id = $_POST[state_id];
		$description = $_POST[description];
		$id = $_REQUEST [id];//获取id	
					
		$b=explode(',',$id);
		$newid  =array();//把id转换为数组
        foreach($b as $v){
        	$newid[] =array($v) ;
        } 
		//dump ($newid);die;
		if (false === $model->create ()) {
			$this->error ( $model->getError () );
		}
		// 更新数据
		foreach ($newid as $val){			
		    $list=$model->where(array('id' => $val[0]))->setField(array('state_id','description'),array("$state_id","$description"));		    
		}
		
		if (false !== $list) {
			//成功提示
			$this->assign ( 'jumpUrl', Cookie::get ( '_currentUrl_' ) );
			$this->success ('验收成功!');
		} else {
			//错误提示
			$this->error ('验收失败!');
		}
	}	
	/**
    * 墓地查询
    */
    function common()
    {		
        $this->display();
    }
  
}

?>